package day4;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
import java.time.*;
/**
 * @author oldliu
 * @since 1.0
 */
public class Birthday2 {
    //完美的还有多少天过生日
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入:");
        String time = input.next();
        SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
        df.setLenient(false);
        Date d=null;
        try {
            d=df.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
            System.out.println("输入错误！");
            return;
        }
        Calendar now=Calendar.getInstance();
        Calendar c=Calendar.getInstance();
        Calendar c0=Calendar.getInstance();
        c0.setTime(d);
        int month=c0.get(Calendar.MONTH);//拿到原来的月份
        int day=c0.get(Calendar.DATE);
        while (true){
            c.set(c.get(Calendar.YEAR),month,day);

            int m2=c.get(Calendar.MONTH);//新月份
            if(m2==month&&(c.after(now)||c.equals(now)))
                break;

            c.add(Calendar.YEAR,1);
        }
        System.out.println(c.getTime()+"   "+now.getTime());
        //算now和C之间的天数
        long days=(c.getTimeInMillis()-now.getTimeInMillis())/(1000*3600*24);
        System.out.println(days);
    }
}
